import { CopyInfoPanelBase } from "../CopyInfoPanelBase";
import { ClockManager } from "../../../manager/ClockManager";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { CrossTowerConfig } from "../../../resource/CrossTowerConfig";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { SCrossTowerInfo } from "../../../../../Message/Public/SCrossTowerInfo";
import { TCrossTowerConfig } from "../../../../../Message/Db/Tables/TCrossTowerConfig";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class CrossTowerCopyInfoPanel
    
    export  class CrossTowerCopyInfoPanel extends CopyInfoPanelBase
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */get nowDate(): Date
        {
            return ClockManager.instance.nowDate;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=NaN;
            var loc2=NaN;
            super.createChildren();
            loc1 = 15;
            loc2 = 150;
            this._remainTimeTxt = ObjCreate.createGTextField(Language.getString(60097), loc1, 30, loc2, 50, this._moveSp, new GTextFormat(FontUtil.songtiName, this._fontSize, 16678400, true));
            this._remainTimeTxt.mouseEnabled = false;
            this._remainTimeShowTxt = ObjCreate.createGTextField("", loc1, 45, loc2, 52, this._moveSp);
            this._remainTimeShowTxt.autoSize = "center";
            this._remainTimeShowTxt.mouseEnabled = false;
            this._conditionTxt = ObjCreate.createGTextField(Language.getString(60412), loc1, 95, loc2, 50, this._moveSp, new GTextFormat(FontUtil.songtiName, this._fontSize, 16742658));
            this._conditionTxt.mouseEnabled = false;
            this._conditionDesTxt = ObjCreate.createGTextField("", loc1, 120, loc2, 100, this._moveSp);
            this._conditionDesTxt.autoSize = "center";
            this._conditionDesTxt.mouseEnabled = false;
            this._remainNumTxt = ObjCreate.createGTextField("", loc1, 195, loc2, 100, this._moveSp, new GTextFormat(FontUtil.songtiName, this._fontSize));
            this._remainNumTxt.mouseEnabled = false;
            return;
        }

        /* internal  */updateRemainTime(): void
        {
            if (this._remainTimeShowTxt) 
            {
                this._remainTimeShowTxt.htmlText = this.getRemainTimeTxt();
            }
            return;
        }

        /* internal  */updConditionDes(): void
        {
            var loc1=null;
            if (this._conditionDesTxt) 
            {
                this._conditionDesTxt.htmlText = this.getConditionDes();
                if (this._info) 
                {
                    loc1 = "<b><font size=\'" + this._fontSize + "\'>" + HTMLUtil.addColor(Language.getString(60079), "#ffff00");
                    loc1 = loc1 + (HTMLUtil.addColor(this._info.totalBossNum - this._info.killBossNum + "/" + this._info.totalBossNum, "#00ff00") + "</font></b>");
                    this._remainNumTxt.htmlText = loc1;
                }
            }
            return;
        }

        /* internal  */startTimer(): void
        {
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer();
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onSecTimerEvent);
            }
            if (!this._secTimer.running) 
            {
                this._secTimer.start();
            }
            return;
        }

        public stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
                this._secTimer.dispose();
                this._secTimer = null;
            }
            return;
        }

        /* internal  */onSecTimerEvent(arg1: SecTimer): void
        {
            this.updateRemainTime();
            if (this._remainSec <= 0) 
            {
                this.stopTimer();
            }
            return;
        }

        /* internal  */getConditionDes(): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc1="<textformat leading=\'3\'><font size=\'12\'>";
            if (this._curTowerConfig && this._info && this._curTowerConfig.floor == this._info.floor) 
            {
                loc2 = Language.getString(20429);
                loc3 = CrossTowerConfig.instance.getBossList(this._curTowerConfig);
                loc4 = loc3.length;
                loc5 = "";
                loc7 = 0;
                while (loc7 < loc4) 
                {
                    loc6 = loc3[loc7];
                    loc5 = loc5 + (loc2 + " " + loc6.name);
                    if (loc7 < (loc4 - 1)) 
                    {
                        loc5 = loc5 + "\n";
                    }
                    ++loc7;
                }
                loc1 = loc1 + HTMLUtil.addColor(loc5, "#ffffff");
            }
            loc1 = loc1 + "</font></textformat>";
            return loc1;
        }

        /* internal  */getRemainTimeTxt(): string
        {
            var loc1="<b><font size=\'" + this._fontSize + "\'>";
            if (this._leftDt) 
            {
                this._remainSec = (this._leftDt.getTime() - this.nowDate.getTime()) / 1000;
                loc1 = loc1 + HTMLUtil.addColor(RemainTimeTool.getRemainTimeBySeconds(this._remainSec, true, false), "#FFFF00");
            }
            loc1 = loc1 + "</font></b>";
            return loc1;
        }

        /* internal  */getFormatTime(arg1: Date): string
        {
            var loc1=arg1.getFullYear() + "年" + (arg1.getMonth() + 1) + "月" + arg1.getDate() + "日";
            loc1 = loc1 + (arg1.getHours() + "时" + arg1.getMinutes() + "分" + arg1.getSeconds() + "秒");
            return loc1;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.setPosition();
            return;
        }

        public /* override */ updateInfos(arg1): void
        {
            var loc1=null;
            if (arg1.nextMap) 
            {
                this._curTowerConfig = arg1.towerConfig;
            }
            else 
            {
                this._info = arg1.info as SCrossTowerInfo;
                this.title = "<font letterSpacing=\'3\' >" + Language.getStringByParam(32090, this._info.floor) + "</font>";
                this._isNextFloor = arg1.isNext;
                if (!this._leftDt) 
                {
                    this._leftDt = this._info.leftDt;
                    this.startTimer();
                }
                if (arg1.isPass == true) 
                {
                    this.stopTimer();
                    loc1 = Language.getString(80257) + Language.getString(40663);
                    this._remainTimeTxt.htmlText = HTMLUtil.addColor(loc1, "#FE7E00");
                }
            }
            this.updConditionDes();
            return;
        }

        public /* override */ hidePanel(): void
        {
            super.hidePanel();
            return;
        }

        public /* override */ showPanel(): void
        {
            super.showPanel();
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this.hide();
            this.stopTimer();
            this._leftDt = null;
            this._info = null;
            this._curTowerConfig = null;
            return;
        }

        /* internal */ /* var */_isNextFloor: Boolean;

        /* internal */ /* var */_curTowerConfig: TCrossTowerConfig;

        /* internal */ /* var */_remainSec: int;

        /* internal */ /* var */_info: SCrossTowerInfo;

        /* internal */ /* var */_leftDt: Date;

        /* internal */ /* var */_remainTimeTxt: GTextFiled;

        /* internal */ /* var */_remainTimeShowTxt: GTextFiled;

        /* internal */ /* var */_conditionTxt: GTextFiled;

        /* internal */ /* var */_conditionDesTxt: GTextFiled;

        /* internal */ /* var */_remainNumTxt: GTextFiled;

        /* internal */ /* var */_fontSize: uint=14;

        /* internal */ /* var */_secTimer: SecTimer;
    }
